<template>
  <div>
    <MyTable :arr="list">
      <template #header>
        <th>#</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>
      <template v-slot:footer="scope" class="my-goods-list">
        <td>{{ scope.row.id }}</td>
        <td>{{ scope.row.goods_name }}</td>
        <td>{{ scope.row.goods_price }}</td>
        <td>
          <!-- <span
            v-for="(str, ind) in scope.row.tags"
            :key="ind"
            class="badge badge-warning"
          >
            {{ str }}
          </span> -->
          {{scope.row.tags[0]}} {{scope.row.tags[1]}}
        </td>
        <td>
          <button class="btn btn-danger btn-sm" @click="delfn(scope.row.id)">删除</button>
        </td>
      </template>
    </MyTable>
  </div>
</template>

<script>
import MyTable from "../components/MyTable.vue";
import axios from "axios";
axios.defaults.baseURL = "https://www.escook.cn";
export default {
  components: {
    MyTable,
  },
  created() {
    axios({
      url: "/api/goods",
    }).then((res) => {
      console.log(res);
      this.list = res.data.data;
    });
  },
  data() {
    return {
      list: [],
    };
  },
  methods:{
    delfn(e){
      console.log(e)
      let index =this.list.findIndex(obj=>obj.id===e)
      console.log(index)
      this.list.splice(e-1,1)
    }
  }
};
</script>

<style lang="less" scoped>
.my-goods-list {
  .badge {
    margin-right: 5px;
  }
}
</style>